<%@page import="transfer.Commodity"%>
<%@page import="java.util.HashMap"%>
<%@page import="transfer.Order"%>
<%@page import="controller.SessionAttribute"%>
<%
    session = request.getSession();
    Order order = (Order) session.getAttribute(SessionAttribute.CART);
    HashMap commodities = null;
    if (order == null || order.getCommodities().size() == 0) {
%>
<script>
    window.location.replace('index.jsp');
</script>
<%} else {
%>
<div class="block">
    <script type="text/javascript" src="js/cart.js"></script>
    <table id="cart-table" border="0" rules=rows bordercolor="#efefef">
        <tr>
            <td width="100px">Items</td>
            <td></td>
            <td width="60px">Quantity</td>
            <td width="120px"  style="text-align: right;">Price</td>
            <td width="40px"></td>
        </tr>
        <%
            commodities = order.getCommodities();
        %>

        <%
            for (int i = 0; i < commodities.size(); i++) {
                Commodity c = (Commodity) commodities.keySet().toArray()[i];
                Integer quantity = (Integer) commodities.values().toArray()[i];
        %>
        <tr id="<%out.print(c.getIdCommodity());%>">
            <td><a href="index.jsp?content=view&id=<%= c.getIdCommodity()%>"><img src="images/commodity/<% out.print(c.getImage());%>"></a></td>
            <td><a href="index.jsp?content=view&id=<%= c.getIdCommodity()%>"><% out.print(c.getNameCommodity());%></a></td>
            <td><input type="number" min="1" step="1" value="<% out.print(quantity.toString());%>" class="inp-amount" onkeydown="javascript: return is_positive_int(event, $(this).val());" onchange="changeCommodityQuantity($(this).parents('tr').attr('id'), this);" ></td>
            <td style="text-align: right;"><b><% out.print(c.getPrice());%> $</b></td>
            <td style="text-align: center; color: red; font-weight: bold;" id="delItem" onclick="removeCommodity($(this).parent().attr('id'));">x</td>
        </tr>
        <%
            }
        %>
    </table>
    <div style="width: 854px; text-align: right; font-size: 16px; font-weight: bold; margin: 5px 0px 5px 0px; padding-top: 15px;">
        <span style="margin-right: 70px;">Total:</span><h id="totalCostCart"><% if (order != null) {
                out.print(order.getCostCommodities());
            } else {
                out.print(0);
            }%></h> $
    </div>
    <%
        if (order != null && !order.getCostCommodities().equals(new Double(0))) {
    %>
    <div style="text-align: center; line-height: 2.5em;">
        <a href="index.jsp?content=order"><input type="button" class="btn-buy" value="Proceed" id="proceed_btn"></a>
    </div>
    <%        }
    %>
</div>
<% } %>